/*
 * MouseEventManager.h
 *
 *  Created on: May 1, 2009
 *      Author: wrice
 */

#ifndef MOUSEEVENTMANAGER_H_
#define MOUSEEVENTMANAGER_H_
#include "PANEApp.h"
namespace PANEApp {

class MouseEventManager {
public:
	MouseEventManager();
	typedef list< MouseEvent * > MouseEvents;
	typedef MouseEvents::const_iterator MouseEventsIterator;

	MyVideoTraceApp * getApp();
	void setApp( MyVideoTraceApp * app );
	void updateView();

	void MouseEventHandler( int event, int x, int y, int flags );

	Node * findEventTarget( Document * doc, int x, int y );
	MouseEvents createMouseEvents( DocumentEvent * target, int event, int x, int y, int flags );
	MouseEvent * createMouseEvent( DocumentEvent * target, string eventtType, int x, int y, int flags, EventTarget * relatedTarget );
	bool dispatchEvent( Event * evt );
	void doDefault();

private:
	typedef map< int, string > EventNameMap;
	typedef pair< int, string > EventNameMapPair;
	typedef EventNameMap::const_iterator EventNameMapIterator;
	EventNameMap eventMap_;

	MouseEventPtr lastEvent_;
	DocumentEvent * lastConsistentClickTarget_;

	MyVideoTraceApp * app_;

	void buildEventNameMap();

public:
	static void on_mouse(int event, int x, int y, int flags, void* parm);

public:	virtual ~MouseEventManager() {}
};

typedef SingletonHolder< MouseEventManager > MouseEventManagerSingleton;

}

#endif /* MOUSEEVENTMANAGER_H_ */
